package com.jhhc.WaterQuality.Calculate.Forecast.service.impl;

import com.jhhc.WaterQuality.Calculate.Forecast.entity.BDMS_SLX_RESULT_M;
import com.jhhc.WaterQuality.Calculate.Forecast.dao.BDMS_SLX_RESULT_MMapper;
import com.jhhc.WaterQuality.Calculate.Forecast.service.BDMS_SLX_RESULT_MService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * (BdmsSlxResultM)表服务实现类
 *
 * @author makejava
 * @since 2023-08-17 11:45:49
 */
@Service("bdmsSlxResultMService")
public class BDMS_SLX_RESULT_MServiceImpl implements BDMS_SLX_RESULT_MService {
    @Resource
    private BDMS_SLX_RESULT_MMapper bdmsSlxResultMDao;

    @Value("${datasourceType}")
    String datasourceType;
    @Override
    public List<BDMS_SLX_RESULT_M> queryByGrids(String cschemeid, Integer grid, int dttp, String startTime, String endTime) {
        return bdmsSlxResultMDao.queryByGrids(cschemeid, grid, dttp, startTime, endTime);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param cschemeid 主键
     * @return 实例对象
     */
    @Override
    public BDMS_SLX_RESULT_M queryById(String cschemeid) {
        return this.bdmsSlxResultMDao.queryById(cschemeid);
    }

    @Override
    public List<BDMS_SLX_RESULT_M> queryAllById(String cschemeid) {
        return bdmsSlxResultMDao.queryAllById(cschemeid);
    }

    /**
     * 分页查询
     *
     * @param BDMSSLXRESULTM 筛选条件
     * @param pageRequest    分页对象
     * @return 查询结果
     */
    @Override
    public Page<BDMS_SLX_RESULT_M> queryByPage(BDMS_SLX_RESULT_M BDMSSLXRESULTM, PageRequest pageRequest) {
        long total = this.bdmsSlxResultMDao.count(BDMSSLXRESULTM);
        return new PageImpl<>(this.bdmsSlxResultMDao.queryAllByLimit(BDMSSLXRESULTM, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param BDMSSLXRESULTM 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(BDMS_SLX_RESULT_M BDMSSLXRESULTM) {
        if ("mysql".equals(datasourceType)){
            return bdmsSlxResultMDao.insert(BDMSSLXRESULTM);
        }else if ("sqlserver".equals(datasourceType)){
            return bdmsSlxResultMDao.insertSqlserver(BDMSSLXRESULTM);
        }
        return 0;
    }

    /**
     * 修改数据
     *
     * @param BDMSSLXRESULTM 实例对象
     * @return 实例对象
     */
    @Override
    public BDMS_SLX_RESULT_M update(BDMS_SLX_RESULT_M BDMSSLXRESULTM) {
        this.bdmsSlxResultMDao.update(BDMSSLXRESULTM);
        return this.queryById(BDMSSLXRESULTM.getCschemeid());
    }

    /**
     * 通过主键删除数据
     *
     * @param cschemeid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String cschemeid) {
        return this.bdmsSlxResultMDao.deleteById(cschemeid) > 0;
    }
}
